home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWARDYNA_H
- #define FWARDYNA_H
- //========================================================================================
- //
- // File: FWArDyna.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWDICTLI_H
- #include "FWDictLi.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // MACROS
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_REGISTER_ARCHIVABLE_CLASS
- //----------------------------------------------------------------------------------------
-
- #define FW_REGISTER_ARCHIVABLE_CLASS(classLabel, classType, inputFunction, outputFunction) \
- FW_CDynamicArchiver FWArchive##classLabel(#classLabel, \
- FW_CLASSNAME_FROM_TYPE(classType), \
- FW_PrivGetLocalNameToLabelMap(), \
- FW_PrivGetLocalLabelToIOFunctionMap(), \
- inputFunction, \
- outputFunction);
-
- //----------------------------------------------------------------------------------------
- // FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS
- //----------------------------------------------------------------------------------------
-
- #define FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS(oldVersionClassLabel, inputFunction) \
- FW_CDynamicArchiver FWArchive##oldVersionClassLabel(#oldVersionClassLabel, \
- FW_PrivGetLocalLabelToIOFunctionMap(), \
- inputFunction);
-
- //----------------------------------------------------------------------------------------
- // FW_REGISTER_ARCHIVABLE_SOM_CLASS
- //----------------------------------------------------------------------------------------
-
- #define FW_REGISTER_ARCHIVABLE_SOM_CLASS(classLabel, classType, inputFunction, outputFunction) \
- FW_CDynamicArchiver FWArchive##classLabel(#classLabel, \
- classType##NewClass(0,0)->somGetName(), \
- FW_PrivGetLocalNameToLabelMap(), \
- FW_PrivGetLocalLabelToIOFunctionMap(), \
- inputFunction, \
- outputFunction);
-
- //----------------------------------------------------------------------------------------
- // FW_ARCHIVE_FUNC_ATTR
- //----------------------------------------------------------------------------------------
-
- // Note: for build configurations that don't have instance data (FW_HAS_INSTANCE_DATA not
- // defined), map merging functions should *NOT* be exported. They must be statically linked
- // in every DLL that defines dynamic classes. The functions are defined in FWLocMap.cpp.
- // Every DLL which registers archivers must statically link to FWLocMap.obj.
-
- #ifdef FW_HAS_INSTANCE_DATA
- #define FW_ARCHIVE_FUNC_ATTR FW_FUNC_ATTR
- #else
- #define FW_ARCHIVE_FUNC_ATTR
- #endif
-
- //========================================================================================
- // Forward Declarations
- //========================================================================================
-
- struct FW_CLASS_ATTR FW_SPrivDynamicArchiverGlobals;
-
- //========================================================================================
- // Struct FW_SPrivArcStr
- // An internal implementation class used in maps for string-type keys and values
- //========================================================================================
-
- struct FW_CLASS_ATTR FW_SPrivArcStr
- {
- public:
- FW_SPrivArcStr(const FW_SPrivArcStr& string);
- FW_SPrivArcStr(const char* string);
- FW_SPrivArcStr& operator=(const FW_SPrivArcStr& string);
- FW_Boolean operator==(const FW_SPrivArcStr& string) const;
- FW_Boolean operator!=(const FW_SPrivArcStr& string) const;
-
- const char* fString;
-
- public:
- // This constructor is necessary as an artifact of the way we use the Booch components.
- // It would be worthwhile to eliminate the need for it when we switch to STL.
- // FW_SPrivArcStr();
- };
-
- //========================================================================================
- // Struct FW_SPrivArcFun
- // An internal implementation class used in maps for I/O function pointer values
- //========================================================================================
-
- struct FW_CLASS_ATTR FW_SPrivArcFun
- {
- FW_SPrivArcFun(const FW_SPrivArcFun& ioFunctions);
- FW_SPrivArcFun(FW_CReadableStream::InputFunction inputFunction,
- FW_CWritableStream::OutputFunction outputFunction);
- FW_SPrivArcFun& operator=(const FW_SPrivArcFun& ioFunctions);
- FW_Boolean operator==(const FW_SPrivArcFun& ioFunctions) const;
- FW_Boolean operator!=(const FW_SPrivArcFun& ioFunctions) const;
-
- FW_CReadableStream::InputFunction fInputFunction;
- FW_CWritableStream::OutputFunction fOutputFunction;
-
- public:
- // This constructor is necessary as an artifact of the way we use the Booch components.
- // It would be worthwhile to eliminate the need for it when we switch to STL.
- // FW_SPrivArcFun();
- };
-
- //========================================================================================
- // Class FW_CPrivNameToLabelMap
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CPrivNameToLabelMap : public FW_CPrivDictionaryList
- {
- public:
- FW_CPrivNameToLabelMap();
- virtual ~FW_CPrivNameToLabelMap();
- protected:
- virtual FW_Boolean KeysMatch(FW_PrivKeyType key1,FW_PrivKeyType key2) const;
- };
-
- //========================================================================================
- // Class FW_CPrivLabelToIOFunctionMap
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CPrivLabelToIOFunctionMap : public FW_CPrivDictionaryList
- {
- public:
- FW_CPrivLabelToIOFunctionMap();
- virtual ~FW_CPrivLabelToIOFunctionMap();
- protected:
- virtual FW_Boolean KeysMatch(FW_PrivKeyType key1,FW_PrivKeyType key2) const;
- };
-
- //========================================================================================
- // STRUCT FW_SPrivDynamicArchiverGlobals
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma options align=mac68k
- #endif
-
- #ifdef FW_BUILD_WIN
- #pragma pack(push, 1)
- #endif
-
- struct FW_CLASS_ATTR FW_SPrivDynamicArchiverGlobals
- {
- FW_CPrivNameToLabelMap * gMapClassNameToClassLabel;
- FW_CPrivLabelToIOFunctionMap * gMapClassLabelToObjectIOFunction;
- };
-
- #ifdef FW_BUILD_MAC
- #pragma options align=reset
- #endif
-
- #ifdef FW_BUILD_WIN
- #pragma pack(pop)
- #endif
-
- //========================================================================================
- // Class FW_CDynamicArchiver
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CDynamicArchiver
- {
-
- public:
-
- static void InputObject(FW_CReadableStream& readableStream,
- void*& object);
- // Input an object of a dynamic class from the readableStream.
-
- static void OutputObject(FW_CWritableStream& writableStream,
- const void* object,
- const char* className);
- // Output an object of a dynamic class to the writableStream.
-
- protected:
-
- enum
- {
- kMaxClassLabelLength = 255 // Maximum allowed length of a class label
- };
-
- static void* ReadClassLabel(FW_CReadableStream& readableStream);
-
- static void WriteClassLabel(FW_CWritableStream& writableStream,
- const void* classLabel);
-
-
- // ----- Task global implementation items
-
- public:
-
- static void Initialize(FW_SPrivDynamicArchiverGlobals& globals);
- static void Terminate();
- static FW_SPrivDynamicArchiverGlobals& GetDynamicArchiverGlobals();
-
- protected:
-
- enum
- {
- kDynamicArchiverGlobalsOffset = 158
- };
-
- // ----- Dynamic map implementation items
-
- public:
-
- friend FW_ARCHIVE_FUNC_ATTR void FW_MergeArchiverMaps();
- friend FW_ARCHIVE_FUNC_ATTR FW_CPrivNameToLabelMap& FW_PrivGetLocalNameToLabelMap();
- friend FW_ARCHIVE_FUNC_ATTR FW_CPrivLabelToIOFunctionMap& FW_PrivGetLocalLabelToIOFunctionMap();
-
- FW_CDynamicArchiver(const char* classLabel,
- const char* className,
- FW_CPrivNameToLabelMap& localNameToLabelMap,
- FW_CPrivLabelToIOFunctionMap& localLabelToIOFunctionMap,
- FW_CReadableStream::InputFunction inputFunction,
- FW_CWritableStream::OutputFunction outputFunction);
- // Register the <classLabel, className, inputFunction, outputFunction>
- // 4-tuple of a dynamic class with the archiver.
-
- FW_CDynamicArchiver(const char* oldVersionClassLabel,
- FW_CPrivLabelToIOFunctionMap& localLabelToIOFunctionMap,
- FW_CReadableStream::InputFunction inputFunction);
- // Registers the <classLabel, inputFunction> for an old label.
-
- static FW_CReadableStream::InputFunction LookupInputFunction(const char* classLabel);
-
- static FW_CWritableStream::OutputFunction LookupOutputFunction(const char* classLabel);
-
- private:
-
- // static BC_Index HashFunction(const FW_SPrivArcStr& string);
-
- static FW_CPrivNameToLabelMap& GetNameToLabelMap();
-
- static FW_CPrivLabelToIOFunctionMap& GetLabelToIOFunctionMap();
-
- static FW_CPrivNameToLabelMap * gLocalClassNameToClassLabelMap;
-
- static FW_CPrivLabelToIOFunctionMap * gLocalClassLabelToObjectIOFunctionMap;
-
- static void MergeNameToLabelMaps(FW_CPrivNameToLabelMap& local,
- FW_CPrivNameToLabelMap& global);
-
- static void MergeLabelToIOFunctionMaps(FW_CPrivLabelToIOFunctionMap& local,
- FW_CPrivLabelToIOFunctionMap& global);
-
- private:
- static FW_SPrivDynamicArchiverGlobals gGlobals;
-
- private:
- FW_CDynamicArchiver(const FW_CDynamicArchiver& archiver);
- FW_CDynamicArchiver& operator=(const FW_CDynamicArchiver& archiver);
- // Shouldn't need to copy this class.
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivNameToLabelMap& FW_CDynamicArchiver::GetNameToLabelMap
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivNameToLabelMap& FW_CDynamicArchiver::GetNameToLabelMap()
- {
- return *GetDynamicArchiverGlobals().gMapClassNameToClassLabel;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivLabelToIOFunctionMap& FW_CDynamicArchiver::GetLabelToIOFunctionMap
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivLabelToIOFunctionMap& FW_CDynamicArchiver::GetLabelToIOFunctionMap()
- {
- return *GetDynamicArchiverGlobals().gMapClassLabelToObjectIOFunction;
- }
-
-
- //========================================================================================
- // Archiver maps implementation functions
- //========================================================================================
-
- FW_ARCHIVE_FUNC_ATTR FW_CPrivNameToLabelMap& FW_PrivGetLocalNameToLabelMap();
-
- FW_ARCHIVE_FUNC_ATTR FW_CPrivLabelToIOFunctionMap& FW_PrivGetLocalLabelToIOFunctionMap();
-
- void FW_ARCHIVE_FUNC_ATTR FW_MergeArchiverMaps();
- // Merge application's or component's archiver map into global archiver map.
-
- void FW_ARCHIVE_FUNC_ATTR FW_InitializeArchiving(FW_Instance rootInstance);
-
- #ifdef FW_BUILD_WIN16
- extern "C" void FW_FUNC_ATTR FW_MERGEARCHIVERMAPSHOOK();
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-